#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif

include $(DEVKITARM)/ds_rules

VER=01
MNT=/mnt/usb2


export TARGET		:=	$(shell basename $(CURDIR))
export TOPDIR		:=	$(CURDIR)


.PHONY: $(TARGET).arm7 $(TARGET).arm9

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all: $(TARGET).ds.gba

install: $(TARGET).nds
	mount $(MNT)
	cp $(TARGET).nds $(MNT)/$(TARGET).nds
	umount $(MNT)

dist: $(TARGET).ds.gba
	rm -f $(TARGET)$(VER).zip
	cp $(TARGET).nds $(TARGET)$(VER).nds
	cp $(TARGET).ds.gba $(TARGET)$(VER).ds.gba
	zip -9 $(TARGET)$(VER).zip $(TARGET)$(VER).nds $(TARGET)$(VER).ds.gba
	scp $(TARGET)$(VER).zip davr@davr.org:httpdocs/ds2

$(TARGET).nef	: arm9/$(TARGET).arm9.elf
	cp arm9/$(TARGET).arm9.elf $(TARGET).nef

$(TARGET).ds.gba	: $(TARGET).nds

#---------------------------------------------------------------------------------
$(TARGET).nds	:	$(TARGET).arm7 $(TARGET).arm9 $(TARGET).nef
	ndstool	-c $(TARGET).nds -7 $(TARGET).arm7 -9 $(TARGET).arm9

#---------------------------------------------------------------------------------
$(TARGET).arm7	: arm7/$(TARGET).elf
$(TARGET).arm9	: arm9/$(TARGET).elf

#---------------------------------------------------------------------------------
arm7/$(TARGET).elf:
	$(MAKE) -C arm7
	
#---------------------------------------------------------------------------------
arm9/$(TARGET).elf:
	$(MAKE) -C arm9

#---------------------------------------------------------------------------------
clean:
	$(MAKE) -C arm9 clean
	$(MAKE) -C arm7 clean
	rm -f $(TARGET)*.ds.gba $(TARGET)*.nds $(TARGET).arm7 $(TARGET).arm9
